/*测试数据*/
var testdata=[
	{
		id: 1,
		productID: 2322,
		productName: "18817802281",
		productBrand: 'lisd',
		productVersion: 'V3高规',
		store: 3455,
		singlePrice: 234,
		tradeCnt: 2234,
		createTime: 1502937009
	},
	{
		id: 2,
		productID: 2322,
		productName: "18817802281",
		productBrand: 'lisd',
		productVersion: 'V3高规',
		store: 3455,
		singlePrice: 234,
		tradeCnt: 2234,
		createTime: 1502937009
	},
	{
		id: 3,
		productID: 2322,
		productName: "18817802281",
		productBrand: 'lisd',
		productVersion: 'V3高规',
		store: 3455,
		singlePrice: 234,
		tradeCnt: 2234,
		createTime: 1502937009
	},
	{
		id: 4,
		productID: 2322,
		productName: "18817802281",
		productBrand: 'lisd',
		productVersion: 'V3高规',
		store: 3455,
		singlePrice: 234,
		tradeCnt: 2234,
		createTime: 1502937009
	}
];

$(function(){
    //getBrandMes();
    getTableData();
});
/*获取品牌数据*/
/*function getBrandMes(){
    var datarows=testdatabrand;
    if(datarows.length>0){
        $("#productBrand").empty();
        $.each(datarows, function(i,item) {
            var $option=$("<option>").val(item.brandName).text(item.brandName);
            $("#productBrand").append($option);
        });
    }else{
        consoleMes($("#manageContent"),3000,"warning","无相关品牌数据，请先添加品牌！");//success、info、warning、danger
        setTimeout(function () {
            window.location.href=gobalWeb+"product/brandmg.html";
        }, 2500);
    }

    $.ajax({
        type: "GET",
        url: gobalWebUrl+"company/getone",
        async: true,//false使用同步的方式,true为异步方式
        data: {"id":tid},
        contentType: "application/json; charset=utf-8",
        dataType: "jsonp",
        jsonp: "callback",
        jsonpCallback:"getone",
        success:function(backData){
            if(backData.result==202){
                var datarows=backData.rows;
                if(datarows.length>0){
                    $("#productBrand").empty();
                    $.each(datarows, function(i,item) {
                        var $option=$("<option>").val(item.brandName).text(item.brandName);
                        $("#productBrand").append($option);
                    });
                }else{
                    consoleMes($("#manageContent"),3000,"warning","无相关品牌数据，请先添加品牌！");//success、info、warning、danger
                    setTimeout(function () {
                        window.location.href=gobalWeb+product/brandmg.html";
                    }, 2500);
                }

            }else{
                consoleMes($("#manageContent"),3000,"warning",backData.message);//success、info、warning、danger
            }
        },
        error:function(backData){

        }
    });
};*/
/*获取表格数据*/
function getTableData(){
	/*var backData=testdata;//[];
	tableInit(backData);*/
    $.post(
        gobalServer+"product/selectAll",
        {},
        function(backData){
            if(backData.statusCode==200){
                var backData=backData.commonList;//[];
                tableInit(backData);
            }else{
                consoleMes($("#manageContent"),2000,"warning",backData.msg);//success、info、warning、danger

            }
        }
    );

};
/*表格初始化*/
function tableInit(backData){
	var objectArray=[];
    if(backData.length>0){
        objectArray=dataToJson(backData);
    }
    $('#stockTable').bootstrapTable('destroy').bootstrapTable({
        toolbar: '#toolbar',                //工具按钮用哪个容器
        pageNumber:1,                       //初始化加载第一页，默认第一页
        pageSize: 20,                       //每页的记录行数（*）
        minimumCountColumns: 2,             //最少允许的列数
        clickToSelect: true,                //是否启用点击选中行
        height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
        data: objectArray,
        pageList: [5, 10, 20, 40, 100, 200]/*,
        rowStyle: function rowStyle(row,index) {
            if(row.mark!=null && row.mark>0){
                return {
                    css:{
                        "background-color": "#ffc930",
                        "color": "#fff"
                    }
                };
            }else{
                return {
                    css:{

                    }
                };
            }
        }*/
    });
};
/*表格数据封装*/
function dataToJson(dataResult) {
    var objectArray=new Array();
    $.each(dataResult,function(index,item){
    	var createTime="--";
    	if(item.createTime!=null){
        	createTime=formatDateTimeYMDHMS(item.createTime);
        }
        var singlePrice="";
        if(item.singlePrice!=null){
        	singlePrice="<b class='text-red'>￥"+item.singlePrice+"</a>";
        }
        /*var opdetail="";
        opdetail="<a class='btn-a-common' href='javascript:;' onclick='getMesDetail("+item.id+")' >查看详情</a>";*/
        var operate="";
        operate="<a class='btn-a-common' href='"+gobalWeb+"orders/createorder.html?tgid="+item.productId+"' >开单</a>";
        var arr={
        	"id":item.id,
        	"productId":item.productId,
            "productName":item.productName,
            "productBrand":item.productBrand,
            "productVersion":item.productVersion,
            "store":item.store,
            "singlePrice":singlePrice,
            "tradeCnt":item.tradeCnt,
            "createTime":createTime,
            "operate":operate
        };
        objectArray.push(arr);
    });
    return objectArray;
};
